//
//  HMUserInfoTools.m
//  获得
//
//  Created by mac on 17/1/9.
//  Copyright © 2017年 mac.gu. All rights reserved.
//

#import "HMUserInfoTools.h"


@interface HMUserInfoTools ()

@property (nonatomic, copy) NSString *fileName;

@end

@implementation HMUserInfoTools

+ (instancetype)shareUserInfo{
    
    static id _instance;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance =[[self alloc]init];
    });
 
    return _instance;
    
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.userModel = [self getModel];
    }
    return self;
}

// 保存模型
- (void)saveModel:(HMUserInfoModel *) model{
    self.userModel = model;
    [NSKeyedArchiver archiveRootObject:model toFile:self.fileName];
}

//获取模型
- (HMUserInfoModel *)getModel{
    return (HMUserInfoModel *)[NSKeyedUnarchiver unarchiveObjectWithFile:self.fileName];
}
//文件路径
- (NSString *)fileName{
    if (!_fileName) {
        NSString * userInfo = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        _fileName = [userInfo stringByAppendingPathComponent:@"userInfo.active"];
    }
    return _fileName;
}

- (NSString *)getModelToekn{
    HMUserInfoModel *model = (HMUserInfoModel *)[NSKeyedUnarchiver unarchiveObjectWithFile:self.fileName];
    return model.token;
}


@end
